package com.fadadianqi.logistics.customer.dao.ibatis;

import com.fadadianqi.commons.GenericDAOSuport;
import com.fadadianqi.logistics.customer.dao.VillageDAO;
import com.fadadianqi.logistics.customer.model.Village;
import com.yeqiangwei.commons.util.Pagination;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class VillageDAOImpl extends GenericDAOSuport<String, Village> implements
        VillageDAO {

    @Override
    public List<Village> findAll() {
        Pagination pagination = new Pagination(1, Integer.MAX_VALUE);
        pagination.setOrderList(new Pagination.Order[]{
                new Pagination.Order("pinyin", Boolean.TRUE)
        });
        return super.findAll(pagination);
    }

    @Override
    public List<Village> findByTownId(String townId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(Village.PROP_TOWN_ID, townId);
        Pagination pagination = new Pagination(1, Integer.MAX_VALUE);
        pagination.setOrderList(new Pagination.Order[]{
                new Pagination.Order("pinyin", Boolean.TRUE)
        });
        map.put("pagination", pagination);
        return super.findByPropertys(map);
    }

    @Override
    protected Class<?> getObjectClass() {
        return Village.class;
    }

    @Override
    protected String getTableName() {
        return "village";
    }

    @Override
    public Village getByName(String name) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(Village.PROP_NAME, name);
        return super.getByPropertys(map);
    }

}
